package map;

import java.util.*;

public class HashMapTest {
    public static void main(String[] args) {
//        HashMap<Student, String> map = new HashMap<>();
//        LinkedHashMap<Student, String> map = new LinkedHashMap<>();
        TreeMap<Student, String> map = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
//                return o1.getName().compareTo(o2.getName());
                if (o1.getAge() != o2.getAge()) {
                    return o1.getAge() - o2.getAge();
                }else {
                    return o1.getName().compareTo(o2.getName());
                }
            }
        });
        Student s1 = new Student("b张三", 11);
        Student s2 = new Student("a李四", 11);
        Student s3 = new Student("王五", 18);
        Student s4 = new Student("赵六", 14);
        Student s5 = new Student("张三", 11);
        map.put(s1,"111");
        map.put(s2,"112");
        map.put(s3,"113");
        map.put(s4,"114");
        map.put(s5,"115");
        for (Map.Entry<Student, String> entry : map.entrySet()) {
            System.out.println(entry.getKey() + "->" + entry.getValue());
        }
        System.out.println("=========================================");
        System.out.println("map.get(\"李四\") = " + map.get(s2));
        System.out.println("map.containsKey(\"王五\") = " + map.containsKey(s3));
        System.out.println("map.containsValue(\"111\") = " + map.containsValue("111"));
        System.out.println("map.remove(\"赵六\") = " + map.remove(s4));
        System.out.println("map.size() = " + map.size());
        System.out.println("==========================================");
        for (Student student : map.keySet()) {
            System.out.println(student + map.get(student));
        }
        System.out.println("==========================================");
        for (Map.Entry<Student, String> entry : map.entrySet()) {
            System.out.println(entry.getKey() + entry.getValue());
        }

        map.clear();
        System.out.println(map.isEmpty());
    }
}
